<?php
if($_FILES["file"]["name"]!="" )
{
$dsize= Dir_size("tmp_upload");
if($dsize>100000)
{echo"Sorry!! No more disk space"; exit;}

if (($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/pjpeg") && ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
   // echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";    
   if (file_exists("./tmp_upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"], "./tmp_upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "./tmp_upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file. File size should be less than 20 KB.";
  }
 }
 
 function Dir_size($dir_name)
 {
$filesizex=0;
$hnd=opendir("./tmp_upload");
while($filex=readdir($hnd))
{	
	if($filex!="." && $filex!="..")
	{//echo "File: ".$filex." Size: ". (filesize("./tmp_upload/".$filex)/1024)."\n";
	$filesizex = $filesizex + filesize("./tmp_upload/".$filex);
	clearstatcache();
	 }	
}
closedir($hnd);
//echo "Directory size: ". ($filesizex/1024);
return $filesizex;
 }
?>
<form method="post" enctype="multipart/form-data" action="File_size_Restriction.php">
  <p>File:
    <input type="file" name="file"><input type="submit" name="Submit" value="Upload">
</p></form>
